<?php

namespace app\api\controller;

use app\admin\model\order\PlayOrder;
use app\common\controller\Api;

use app\admin\model\biz\BizInfo;
/**
 * 订单接口
 *
 * 订单状态 0 取消 1下单 2已支付 3拒绝 4已接单 5 进行中 6 完成
 */
class Order extends Api
{
    protected $noNeedLogin = [];
    protected $noNeedRight = '*';



    public function create(){
        $params=$this->request->post();
        $params['uid']=$this->uid();
        try {
            $result=(new PlayOrder())->createOrder($params);
            $this->success('',$result);
        }catch (\Exception $e){
            $this->error($e->getMessage());
        }

    }

    public function cancel(){
        $id=$this->request->post('id');
        $result=(new PlayOrder())->cancel($id,$this->uid());
        $this->success('',$result);
    }

    public function refuse(){
        $id=$this->request->post('id');
        $result=(new PlayOrder())->refuse($id,$this->uid());
        $this->success('',$result);

    }

    public function accept(){
        $id=$this->request->post('id');
        $result=(new PlayOrder())->accept($id,$this->uid());
        $this->success('',$result);

    }

    public function info(){
        $id=$this->request->post('id');
        $from=$this->request->post('from');
        $lat=$this->request->post('lat');
        $lng=$this->request->post('lng');
        $result=(new PlayOrder())->detail($id,$this->uid(),$from,$lat,$lng);
        $this->success('',$result);

    }
    public function list(){
        $type=$this->request->post('type',1);
        $page=$this->request->post('page',1);
        $status=$this->request->post('status');
        $where=$type==1?['uid'=>$this->uid()]:['player_id'=>$this->uid()];
        $query=(new PlayOrder())->where($where);
        if($status)  $query->where(['status'=>$status]);
        $list=$query->page($page)->select();
        $this->success('',$list);
    }

}
